package com.home.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.home.common.Cache;
import com.home.model.HouseAge;
import com.home.service.HouseAgeService;

@Controller
public class HouseAgeAction {
	@Autowired
	private HouseAgeService houseAgeService;

	public HouseAgeService getHouseAgeService() {
		return houseAgeService;
	}

	public void setHouseAgeService(HouseAgeService houseAgeService) {
		this.houseAgeService = houseAgeService;
	}
	@RequestMapping("/admin/houseage/list.do")
	public String getAll(HttpServletRequest request) {
		List<HouseAge> houseAgeList = this.getHouseAgeService().getList();
		request.setAttribute("list", houseAgeList);
		return "/admin/houseage/list";
	}

	@RequestMapping("/admin/houseage/save.do")
	public String getAll(HouseAge houseAge) {
		if (houseAge != null) {
			this.getHouseAgeService().save(houseAge);
		}
		Cache.getInstance().refreshHouseAge();
		return "redirect:/admin/houseage/list.do";
	}

	@RequestMapping("/admin/houseage/get.do")
	public String getAll(Integer id, HttpServletRequest request) {
		if (id != null) {
			HouseAge houseAge = this.getHouseAgeService().getHouseAge(id);
			request.setAttribute("obj", houseAge);
		}
		return "/admin/houseage/obj";
	}
	
	
	@RequestMapping("/admin/houseage/delete.do")
	public String delete(Integer id, HttpServletRequest request) {
		if (id != null) {
			HouseAge houseAge=new HouseAge();
			houseAge.setId(id);
			this.getHouseAgeService().delete(houseAge);
		}
		return "redirect:/admin/houseage/list.do";
	}
}
